﻿namespace Raven
{
    public class TriggerSoundNotify : TriggerLimitedLifeTime<RavenBot>
    {
        //a pointer to the bot that has made the sound
        private RavenBot _soundSource;
        private RavenGame _world;

        public TriggerSoundNotify(RavenBot bot, RavenGame world, Fix range) : base(EntityType.SoundNotify, Constants.SoundNotify_LifeTime)
        {
            _world = world;
            _soundSource = bot;
            SetPos(bot.Pos());
            SetBRadius(range);
            AddCircularTriggerRegion(Pos(), BRadius());
        }

        public override void Try(RavenBot entity)
        {
            //is this bot within range of this sound
            if (isTouchingTrigger(entity.Pos(), entity.BRadius()))
            {
                _world.Dispatcher.DispatchMsg(Constants.SEND_MSG_IMMEDIATELY,
                    Constants.SENDER_ID_IRRELEVANT,
                    entity.ID(),
                    MessageType.Msg_GunshotSound,
                    _soundSource);
            }
        }
    }
}